﻿using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XNA_TD
{
    public class ButtonPressed : IRunable, IUpdate
    {
        MouseState oldMouseState;
        MouseState mouseState;

        KeyboardState oldKeyboardState;
        KeyboardState keyboardState;

        public ButtonPressed()
            : base(Priority.Logic)
        {
            Update();
            Update();

            buttonPressed = this;
            Register(this);
        }

        public bool MouseRightButtonPressed()
        {
            return mouseState.RightButton == ButtonState.Pressed && oldMouseState.RightButton == ButtonState.Released;
        }
        public bool MouseLeftButtonPressed()
        {
            return mouseState.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton == ButtonState.Released;
        }

        public bool KeyPressed(Keys key)
        {
            return keyboardState.IsKeyDown(key) && oldKeyboardState.IsKeyUp(key); 
        }

        public void Update()
        {
            oldMouseState = mouseState;
            mouseState = Mouse.GetState();

            oldKeyboardState = keyboardState;
            keyboardState = Keyboard.GetState();
        }

        public override void Load()
        {
        }

        public override void UnLoad()
        {
        }
    }
}
